import json

# 准备列表，列表内每个元素都是字典，将其转换成json
data = [{'name':'李健奇','sex':'男','age':'22'},{'name':'张大喵','sex':'男','age':'23'},{'name':'王大锤','sex':'男','age':'20'}]
json_str = json.dumps(data,ensure_ascii=False)
print(type(json_str))
print(json_str)

# 准备字典，将其转换成json
d = {'name':'钟离','addr':'璃月'}
d_str = json.dumps(d,ensure_ascii=False)
print(type(d_str))
print(d_str)

# 将json字符串转换为Python数据类型
s =' [{"name": "李健奇", "sex": "男", "age": "22"}, {"name": "张大喵", "sex": "男", "age": "23"}, {"name": "王大锤", "sex": "男", "age": "20"}]'
l = json.loads(s)
print(type(l))
print(l)

s = '{"name": "钟离", "addr": "璃月"}'
d = json.loads(s)
print(type(d))
print(d)